package com.gemfire.onlineretailer.domain;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;

public class Clothing extends Item implements DataSerializable {

	  public static final long CLOTHING_1 = 10000001;
	  public static final long CLOTHING_2 = 10000002;

	  public static final long CLOTHING_3 = 10000003;
	  public static final long CLOTHING_4 = 10000004;
	  public static final long CLOTHING_5 = 10000005;
	  
	  public static final String CLOTHING_1_CODE = "10000001";
	  public static final String CLOTHING_2_CODE = "10000002";

	  public static final String CLOTHING_3_CODE = "10000003";
	  public static final String CLOTHING_4_CODE = "10000004";
	  public static final String CLOTHING_5_CODE = "10000005";
	  
	  public static final String CLOTHING_1_COLOR = "Red";
	  public static final String CLOTHING_2_COLOR = "Yelow";
	  public static final String CLOTHING_3_COLOR = "Blue";
	  public static final String CLOTHING_4_COLOR = "Purple";
	  public static final String CLOTHING_5_COLOR = "White";
	  
	  public static final int CLOTHING_1_WAIST = 28;
	  public static final int CLOTHING_2_WAIST = 30 ;
	  public static final int CLOTHING_3_WAIST = 32;
	  public static final int CLOTHING_4_WAIST = 34;
	  public static final int CLOTHING_5_WAIST = 36;
	  
	  public static final int CLOTHING_1_LENGTH = 28;
	  public static final int CLOTHING_2_LENGTH = 30 ;
	  public static final int CLOTHING_3_LENGTH = 32;
	  public static final int CLOTHING_4_LENGTH = 34;
	  public static final int CLOTHING_5_LENGTH = 36;
	  
	  public static final float CLOTHING_1_ORIGNAL_PRICE = 28.00f;
	  public static final float CLOTHING_2_ORIGNAL_PRICE = 30.00f ;
	  public static final float CLOTHING_3_ORIGNAL_PRICE = 32.00f;
	  public static final float CLOTHING_4_ORIGNAL_PRICE = 34.00f;
	  public static final float CLOTHING_5_ORIGNAL_PRICE = 36.00f;
	  
	  public static final float CLOTHING_1_DICCOUNT_PRICE = 20.00f;
	  public static final float CLOTHING_2_DICCOUNT_PRICE = 25.00f ;
	  public static final float CLOTHING_3_DICCOUNT_PRICE = 27.00f;
	  public static final float CLOTHING_4_DICCOUNT_PRICE = 24.00f;
	  public static final float CLOTHING_5_DICCOUNT_PRICE = 23.00f;
	  
	private int clothingType;
	private int clothingGender;
	private String color;
	private int waist;
	private int length;
	private int size;
	private float originalPrice;
	private float discount;
	private boolean clearance;
	
	
	public Clothing(){
		super();
	}

	

	public int getClothingType() {
		return clothingType;
	}



	public void setClothingType(int clothingType) {
		this.clothingType = clothingType;
	}



	public int getClothingGender() {
		return clothingGender;
	}



	public void setClothingGender(int clothingGender) {
		this.clothingGender = clothingGender;
	}



	public String getColor() {
		return color;
	}



	public void setColor(String color) {
		this.color = color;
	}



	public int getWaist() {
		return waist;
	}



	public void setWaist(int waist) {
		this.waist = waist;
	}



	public int getLength() {
		return length;
	}



	public void setLength(int length) {
		this.length = length;
	}



	public int getSize() {
		return size;
	}



	public void setSize(int size) {
		this.size = size;
	}



	public float getOriginalPrice() {
		return originalPrice;
	}



	public void setOriginalPrice(float originalPrice) {
		this.originalPrice = originalPrice;
	}



	public float getDiscount() {
		return discount;
	}



	public void setDiscount(float discount) {
		this.discount = discount;
	}



	public boolean isClearance() {
		return clearance;
	}



	public void setClearance(boolean clearance) {
		this.clearance = clearance;
	}



	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		this.clothingType = in.readInt();
		this.clothingGender = in.readInt();;
		this.color = in.readUTF();
		this.waist = in.readInt();
		this.length = in.readInt();
		this.size = in.readInt();
		this.originalPrice = in.readFloat();
		this.discount = in.readFloat();
		this.clearance = in.readBoolean();
		
	}


	@Override
	public void toData(DataOutput out) throws IOException {
		
		out.writeInt(this.clothingType);
		out.writeInt(this.clothingGender);
		out.writeUTF(this.color);
		out.writeInt(this.waist);
		out.writeInt(this.length);
		out.writeInt(this.size);
		out.writeFloat(this.originalPrice);
		out.writeFloat(this.discount);
		out.writeBoolean(this.clearance);

	}
	
public static Clothing createInstance(long clothingId){
		
		/*
		 * Use itemId to read from DB or from other source, Hardcode for now
		 */
		
		Clothing clothing = new Clothing();
		
		if (clothingId == CLOTHING_1){
			clothing.setItemId(clothingId);
			clothing.setClothingType(ClothingType.JACKET.getCode());
			clothing.setClearance(false);
			clothing.setClothingGender(ClothingGender.MALE.getCode());
			clothing.setWaist(CLOTHING_1_WAIST);
			clothing.setLength(CLOTHING_1_LENGTH);
			clothing.setOriginalPrice(CLOTHING_1_ORIGNAL_PRICE);
			clothing.setDiscount(CLOTHING_1_DICCOUNT_PRICE);
			clothing.setReorderLevel(20);
		} 
		else if (clothingId == CLOTHING_2){
			clothing.setItemId(clothingId);
			clothing.setClothingType(ClothingType.JEANS.getCode());
			clothing.setClearance(false);
			clothing.setClothingGender(ClothingGender.FEMALE.getCode());
			clothing.setWaist(CLOTHING_2_WAIST);
			clothing.setLength(CLOTHING_2_LENGTH);
			clothing.setOriginalPrice(CLOTHING_2_ORIGNAL_PRICE);
			clothing.setDiscount(CLOTHING_2_DICCOUNT_PRICE);
			clothing.setReorderLevel(20);
		} 
		else if (clothingId == CLOTHING_3){
			clothing.setItemId(clothingId);
			clothing.setClothingType(ClothingType.SHIRT.getCode());
			clothing.setClearance(false);
			clothing.setClothingGender(ClothingGender.MALE.getCode());
			clothing.setWaist(CLOTHING_3_WAIST);
			clothing.setLength(CLOTHING_3_LENGTH);
			clothing.setOriginalPrice(CLOTHING_3_ORIGNAL_PRICE);
			clothing.setDiscount(CLOTHING_3_DICCOUNT_PRICE);
			clothing.setReorderLevel(20);
		} 
		else if (clothingId == CLOTHING_4){
			clothing.setItemId(clothingId);
			clothing.setClothingType(ClothingType.JEANS.getCode());
			clothing.setClearance(false);
			clothing.setClothingGender(ClothingGender.FEMALE.getCode());
			clothing.setWaist(CLOTHING_4_WAIST);
			clothing.setLength(CLOTHING_4_LENGTH);
			clothing.setOriginalPrice(CLOTHING_4_ORIGNAL_PRICE);
			clothing.setDiscount(CLOTHING_4_DICCOUNT_PRICE);
			clothing.setReorderLevel(20);
		}
		else {
			clothing.setItemId(clothingId);
			clothing.setClothingType(ClothingType.TROUSER.getCode());
			clothing.setClearance(false);
			clothing.setClothingGender(ClothingGender.MALE.getCode());
			clothing.setWaist(CLOTHING_5_WAIST);
			clothing.setLength(CLOTHING_5_LENGTH);
			clothing.setOriginalPrice(CLOTHING_5_ORIGNAL_PRICE);
			clothing.setDiscount(CLOTHING_5_DICCOUNT_PRICE);
			clothing.setReorderLevel(20);
			} 
		
		return clothing;
		
	}
	
	
}
